package com.itheima.controller;

import com.itheima.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {

    @RequestMapping("/hello")
    public String hello(Model model,String id){
        model.addAttribute("hello","hello welcome");
        System.out.println("接收的值为："+id);

        //list集合
        List<User> list = new ArrayList<>();
        list.add(new User(1,"张三","上海"));
        list.add(new User(2,"李四","北京"));
        list.add(new User(3,"王五","广州"));
        model.addAttribute("list",list);

        //map集合
        Map<String,Object> map = new HashMap<>();
        map.put("No","123");
        map.put("Yes","Good");
        model.addAttribute("dateMap",map);

        //数组
        String[] names = {"张三","李四","王五"};
        model.addAttribute("names",names);

        //日期
        model.addAttribute("now",new Date());

        //if条件判断
        model.addAttribute("age",22);
        return "demo";
    }

}
